package mulMan.gui.view;

import java.util.Observable;
import java.util.Observer;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import mulMan.domain.AudioFile;

public abstract class AudioFileView extends JFrame  implements Observer {

	private static final long serialVersionUID = -1833973059123903566L;
	
	private AudioFile audioFile;
	private JTextField titleTextField;
	private JTextField albumTextField;
	private JTextField artistTextField;
	private JTextField lengthTextField;
	private JTextField pathTextField;
	private JPanel panel;

	public AudioFile getAudioFile() {
		return audioFile;
	}
	public void setAudioFile(AudioFile audioFile) {
		this.audioFile = audioFile;
	}
	public JTextField getTitleTextField() {
		return titleTextField;
	}
	public void setTitleTextField(JTextField titleTextField) {
		this.titleTextField = titleTextField;
	}
	public JTextField getAlbumTextField() {
		return albumTextField;
	}
	public void setAlbumTextField(JTextField albumTextField) {
		this.albumTextField = albumTextField;
	}
	public JTextField getArtistTextField() {
		return artistTextField;
	}
	public void setArtistTextField(JTextField artistTextField) {
		this.artistTextField = artistTextField;
	}
	public JTextField getLengthTextField() {
		return lengthTextField;
	}
	public void setLengthTextField(JTextField lengthTextField) {
		this.lengthTextField = lengthTextField;
	}
	public JTextField getPathTextField() {
		return pathTextField;
	}
	public void setPathTextField(JTextField pathTextField) {
		this.pathTextField = pathTextField;
	}
	public JPanel getPanel() {
		return panel;
	}
	public void setPanel(JPanel panel) {
		this.panel = panel;
	}
	
	
	public AudioFileView(AudioFile audioFile) {
		this.audioFile = audioFile;
		this.audioFile.addObserver(this);
		
		initView();
	    initFields();
	}

	public void update(Observable o, Object arg) {
		if (arg == "title") {
			titleTextField.setText(audioFile.getTitle());
		}
		if (arg == "album") {
			albumTextField.setText(audioFile.getAlbum());
		}
		if (arg == "artist") {
			artistTextField.setText(audioFile.getArtist());
		}
		if (arg == "length") {
			lengthTextField.setText(String.valueOf(audioFile.getLength()));
		}
		if (arg == "path") {
			pathTextField.setText(audioFile.getPath());
		}
	}

	public void initView() {
		panel = new JPanel();
	    getContentPane().add(panel);
	    panel.setLayout(null);
	       
	    
		setTitle("Audio file window");
	    setSize(300, 200);
	    setLocationRelativeTo(null);
	    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
	    setVisible(true);
	    
	    JLabel label1 = new JLabel();
	    label1.setText("title: ");
	    label1.setBounds(0, 0, 80, 20);
	    panel.add(label1);
	    titleTextField = new JTextField();
	    titleTextField.setBounds(80, 0, 120, 20);
	    panel.add(titleTextField);
	    
	    JLabel label2 = new JLabel();
	    label2.setText("album: ");
	    label2.setBounds(0, 20, 80, 20);
	    panel.add(label2);
	    albumTextField = new JTextField();
	    albumTextField.setBounds(80, 20, 120, 20);
	    panel.add(albumTextField);
	    
	    JLabel label3 = new JLabel();
	    label3.setText("artist: ");
	    label3.setBounds(0, 40, 80, 20);
	    panel.add(label3);
	    artistTextField = new JTextField();
	    artistTextField.setBounds(80, 40, 120, 20);
	    panel.add(artistTextField);
	    
	    JLabel label4 = new JLabel();
	    label4.setText("length: ");
	    label4.setBounds(0, 60, 80, 20);
	    panel.add(label4);
	    lengthTextField = new JTextField();
	    lengthTextField.setBounds(80, 60, 120, 20);
	    panel.add(lengthTextField);
	    
	    JLabel label5 = new JLabel();
	    label5.setText("path: ");
	    label5.setBounds(0, 80, 80, 20);
	    panel.add(label5);
	    pathTextField = new JTextField();
	    pathTextField.setBounds(80, 80, 120, 20);
	    panel.add(pathTextField);
	}
	
	public void initFields() {
		titleTextField.setText(audioFile.getTitle());
	    albumTextField.setText(audioFile.getAlbum());
	    artistTextField.setText(audioFile.getArtist());
	    lengthTextField.setText(String.valueOf(audioFile.getLength()));
	    pathTextField.setText(audioFile.getPath());
	}
}
